﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Flight Search
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <form id="form1" runat="server">
    <h1>
        Flight Search</h1>
    <br />
    <% using (Html.BeginForm())
       { %>
    <fieldset>
        <table>
            <tr>
                <td>
                    Departure :
                </td>
                <td>
                    <%= Html.DropDownList("Origin", (SelectList)ViewData["AirportList"], new { style = "width: 99%;" })%>
                </td>
            </tr>
            <tr>
                <td>
                    Arrival :
                </td>
                <td>
                    <%= Html.DropDownList("Destination", (SelectList)ViewData["AirportList"], new { style = "width: 99%;" })%>
                </td>
                <td>
                    <%= Html.ValidationMessage("Destination") %>
                </td>
            </tr>
            <tr>
                <td>
                    Departure Date :
                </td>
                <td>
                    <%= Html.TextBox("DepartureDate", ViewData["DepartureDate"], new { @class = "UseDatePicker" })%>
                </td>
                <td>
                    <%= Html.ValidationMessage("DepartureDate")%>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <%= Html.RadioButton("TripType", "OneWayTrip", true)%>One way
                    <%= Html.RadioButton("TripType", "ReturnTrip")%>Return
                </td>
            </tr>
            <tr>
                <td>
                    Return Date :
                </td>
                <td>
                    <%= Html.TextBox("ReturnDate", ViewData["ReturnDate"], new { @class = "UseDatePicker", @disabled = "disabled"})%>
                </td>
                <td>
                    <%= Html.ValidationMessage("ReturnDate") %>
                </td>
            </tr>
            <tr class="ReturnDateRow">
                <td>
                    Type :
                </td>
                <td>
                    <%= Html.DropDownList("SeatType", new SelectList(ViewData["SeatTypeList"] as IEnumerable<SelectListItem>, "Value", "Text"), new { style = "width: 99%;" })%>
                </td>
            </tr>
            <tr>
                <td>
                    Passengers :
                </td>
                <td>
                    <%= Html.DropDownList("Pax", new SelectList(ViewData["PaxList"] as IEnumerable<SelectListItem>, "Value", "Text"), new { style = "width: 99%;" })%>
                </td>
            </tr>
        </table>
    </fieldset>
    <div>
        <input type="submit" value="Find Schedules" class="yellow_button" />
    </div>
    <br />
    <% } %>
    </form>
    <script type="text/javascript">
        $(document).ready(function () {
            showHideReturnDateDiv();
            $("#TripType[value='ReturnTrip']").change(showHideReturnDateDiv);
            $("#TripType[value='OneWayTrip']").change(showHideReturnDateDiv);

            function showHideReturnDateDiv() {
                if ($("#TripType[value='ReturnTrip']").is(':checked') == true) {
                    $("#ReturnDate").removeAttr('disabled');
                } else {
                    $("#ReturnDate").val('');
                    $("#ReturnDate").attr('disabled', 'disabled');
                }
            }

            changeDestination();
            $("#Origin").change(changeDestination);
            function changeDestination() {
                if ($("#Origin").val() == $("#Destination").val()) {
                    if ($("#Destination").val() == $("#Destination > option").first().val()) {
                        $("#Destination").val($("#Destination > option").next().val());
                    } else {
                        $("#Destination").val($("#Destination > option").first().val());
                    }
                }
            }
        });
    </script>
</asp:Content>
